// pages/services/services.ts

interface ServiceItem {
  id: number;
  name: string;
  category: string;
  icon: string;
  iconColor: string;
  tags: string[];
  description: string;
  image: string;
  images: string[];
  providers: Array<{
    id: number;
    name: string;
    rating: number;
    address: string;
  }>;
  benefits: Array<{
    title: string;
    content: string;
  }>;
}

interface CategoryItem {
  id: string;
  name: string;
  icon: string;
  count: number;
}

Page({
  data: {
    searchValue: '',
    activeTab: 'all',
    services: [] as ServiceItem[],
    filteredServices: [] as ServiceItem[],
    
    // 分类数据
    categories: [
      { id: 'all', name: '全部', icon: 'app', count: 8 },
      { id: 'health', name: '健康管理', icon: 'heart', count: 2 },
      { id: 'spa', name: '中医SPA', icon: 'user', count: 2 },
      { id: 'food', name: '药膳营养', icon: 'shop', count: 2 },
      { id: 'forest', name: '森林疗法', icon: 'image', count: 1 },
      { id: 'hot_spring', name: '温泉疗法', icon: 'flag', count: 1 }
    ] as CategoryItem[]
  },

  onLoad: function () {
    this.loadServicesData();
  },

  // 加载服务数据
  loadServicesData: function () {
    // 模拟API请求获取服务数据
    wx.showLoading({
      title: '加载中',
    });
    
    setTimeout(() => {
      const services: ServiceItem[] = [
        {
          id: 1,
          name: '全面体检套餐',
          category: 'health',
          icon: 'heart',
          iconColor: '#0052d9',
          tags: ['健康评估', '体检'],
          description: '提供全面的身体健康检查，包括血液检测、影像学检查、心肺功能评估等，由专业医生提供个性化健康报告和建议。',
          image: 'https://images.unsplash.com/photo-1584982751601-97dcc096659c',
          images: [
            'https://images.unsplash.com/photo-1584982751601-97dcc096659c',
            'https://images.unsplash.com/photo-1526718583451-1ce644c4f010',
            'https://images.unsplash.com/photo-1579154392429-0e6b4e615a10'
          ],
          providers: [
            { id: 1, name: '贵州省康养中心', rating: 4.8, address: '贵阳市观山湖区金阳南路6号' },
            { id: 2, name: '黔南国际康养医院', rating: 4.7, address: '黔南州都匀市匀东镇健康路88号' }
          ],
          benefits: [
            { title: '全面评估', content: '全面评估身体各系统健康状况，及早发现潜在健康风险' },
            { title: '专家解读', content: '由专业医生一对一解读体检报告，提供个性化健康建议' },
            { title: '跟踪管理', content: '提供长期健康管理计划，定期回访，跟踪健康状况变化' }
          ]
        },
        {
          id: 2,
          name: '亚健康调理',
          category: 'health',
          icon: 'user',
          iconColor: '#00a870',
          tags: ['疲劳调理', '睡眠改善'],
          description: '针对现代人常见的亚健康状态，如疲劳、失眠、压力大等问题，提供综合调理方案，恢复身心活力。',
          image: 'https://images.unsplash.com/photo-1600334129128-685c5582fd35',
          images: [
            'https://images.unsplash.com/photo-1600334129128-685c5582fd35',
            'https://images.unsplash.com/photo-1620916566256-3753a9eca502',
            'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b'
          ],
          providers: [
            { id: 3, name: '贵州传统医学研究院', rating: 4.9, address: '贵阳市云岩区延安中路128号' },
            { id: 4, name: '黔东南苗医康养中心', rating: 4.6, address: '黔东南州凯里市开发区健康路10号' }
          ],
          benefits: [
            { title: '综合调理', content: '结合中医理论，针对个人体质特点，制定个性化调理方案' },
            { title: '改善症状', content: '有效改善疲劳感、睡眠质量、注意力不集中等亚健康症状' },
            { title: '提升活力', content: '通过饮食调整、运动指导、心理疏导等方式，全面提升身心活力' }
          ]
        },
        {
          id: 3,
          name: '中医经络SPA',
          category: 'spa',
          icon: 'swap',
          iconColor: '#0052d9',
          tags: ['舒缓压力', '经络疏通'],
          description: '结合传统中医经络理论和现代SPA技术，通过专业手法疏通经络，调和气血，缓解疲劳，促进身心放松。',
          image: 'https://images.unsplash.com/photo-1470259078422-826894b933aa',
          images: [
            'https://images.unsplash.com/photo-1470259078422-826894b933aa',
            'https://images.unsplash.com/photo-1544161515-4ab6ce6db874',
            'https://images.unsplash.com/photo-1596462502278-27bfdc403348'
          ],
          providers: [
            { id: 5, name: '贵州省中医院康养中心', rating: 4.8, address: '贵阳市南明区甲秀南路25号' },
            { id: 6, name: '贵阳颐养轩SPA会所', rating: 4.7, address: '贵阳市观山湖区金阳北路226号' }
          ],
          benefits: [
            { title: '缓解疲劳', content: '有效缓解身体疲劳，舒缓肌肉紧张，改善睡眠质量' },
            { title: '调和气血', content: '通过穴位刺激和经络疏通，促进气血循环，增强体质' },
            { title: '心灵放松', content: '在舒适的环境中释放压力，平衡身心，提升生活品质' }
          ]
        },
        {
          id: 4,
          name: '苗医药浴',
          category: 'spa',
          icon: 'image',
          iconColor: '#ed7b2f',
          tags: ['民族特色', '草药养生'],
          description: '传承贵州苗族传统药浴技艺，采用当地名贵草药，配合专业技术，通过药浴方式促进血液循环，缓解疲劳，改善亚健康状态。',
          image: 'https://images.unsplash.com/photo-1515377905703-c4788e51af15',
          images: [
            'https://images.unsplash.com/photo-1515377905703-c4788e51af15',
            'https://images.unsplash.com/photo-1507652313519-d4e9174996dd',
            'https://images.unsplash.com/photo-1531189519358-5cadb56b3a50'
          ],
          providers: [
            { id: 7, name: '雷山苗医苗药中心', rating: 4.9, address: '黔东南州雷山县西江镇苗寨路18号' },
            { id: 8, name: '贵阳苗医堂', rating: 4.6, address: '贵阳市观山湖区金阳南路128号' }
          ],
          benefits: [
            { title: '草药功效', content: '精选20余种贵州高山草药，具有舒筋活血、清热解毒等多种功效' },
            { title: '促进循环', content: '药浴过程中草药有效成分通过皮肤吸收，促进血液循环，加速新陈代谢' },
            { title: '民族特色', content: '体验贵州苗族传统医疗文化，享受独特的康养体验' }
          ]
        },
        {
          id: 5,
          name: '森林康养',
          category: 'forest',
          icon: 'root-list',
          iconColor: '#00a870',
          tags: ['森林浴', '自然疗法'],
          description: '在森林覆盖率高的贵州山区，开展森林步道、森林呼吸、森林瑜伽等活动，通过吸收负氧离子和植物挥发的芬多精，提高身体免疫力。',
          image: 'https://images.unsplash.com/photo-1448375240586-882707db888b',
          images: [
            'https://images.unsplash.com/photo-1448375240586-882707db888b',
            'https://images.unsplash.com/photo-1470770841072-f978cf4d019e',
            'https://images.unsplash.com/photo-1441974231531-c6227db76b6e'
          ],
          providers: [
            { id: 9, name: '贵州森林康养基地', rating: 4.8, address: '贵阳市修文县扎佐镇大湾村' },
            { id: 10, name: '荔波喀斯特森林疗养中心', rating: 4.9, address: '黔南州荔波县小七孔景区附近' }
          ],
          benefits: [
            { title: '呼吸调节', content: '森林中负氧离子含量高，有助于改善呼吸系统功能，缓解呼吸道不适' },
            { title: '压力缓解', content: '自然环境中的色彩、声音、气味等元素能有效减轻压力，改善心理状态' },
            { title: '提高免疫', content: '森林中的芬多精能激活自然杀手细胞，增强人体免疫力' }
          ]
        },
        {
          id: 6,
          name: '温泉疗养',
          category: 'hot_spring',
          icon: 'flag',
          iconColor: '#0052d9',
          tags: ['温泉浴', '矿物质疗法'],
          description: '利用贵州丰富的温泉资源，提供专业温泉疗养服务，温泉中的矿物质和微量元素可以通过皮肤吸收，对多种慢性疾病有辅助治疗作用。',
          image: 'https://images.unsplash.com/photo-1571401835393-8c5f35328320',
          images: [
            'https://images.unsplash.com/photo-1571401835393-8c5f35328320',
            'https://images.unsplash.com/photo-1584491258040-35200efc2d6e',
            'https://images.unsplash.com/photo-1610445802905-d8ada284f5a7'
          ],
          providers: [
            { id: 11, name: '贵州温泉康养中心', rating: 4.7, address: '贵阳市开阳县城关镇温泉路18号' },
            { id: 12, name: '石阡温泉度假村', rating: 4.8, address: '铜仁市石阡县温泉镇河滨路1号' }
          ],
          benefits: [
            { title: '缓解疼痛', content: '温泉浴可以舒缓肌肉疼痛，减轻关节不适，对风湿性疾病有一定辅助治疗作用' },
            { title: '皮肤健康', content: '温泉中的矿物质和硫化物对多种皮肤问题有改善作用，促进皮肤新陈代谢' },
            { title: '改善睡眠', content: '温泉浴后体温缓慢下降的过程有助于提高睡眠质量，改善失眠问题' }
          ]
        },
        {
          id: 7,
          name: '药膳调理',
          category: 'food',
          icon: 'shop',
          iconColor: '#ed7b2f',
          tags: ['营养调理', '中医饮食'],
          description: '结合中医理论和现代营养学，根据个人体质特点，量身定制药膳食疗方案，通过饮食调理改善健康状态。',
          image: 'https://images.unsplash.com/photo-1621939514649-280e2ee25f60',
          images: [
            'https://images.unsplash.com/photo-1621939514649-280e2ee25f60',
            'https://images.unsplash.com/photo-1546069901-ba9599a7e63c',
            'https://images.unsplash.com/photo-1547592180-85f173990554'
          ],
          providers: [
            { id: 13, name: '贵州省中医院营养科', rating: 4.6, address: '贵阳市南明区甲秀南路25号' },
            { id: 14, name: '贵阳药膳坊', rating: 4.5, address: '贵阳市云岩区中华北路156号' }
          ],
          benefits: [
            { title: '平衡调理', content: '根据"药食同源"理念，通过食疗平衡阴阳，调和气血，改善体质' },
            { title: '营养强化', content: '精选优质食材和药材，补充人体所需营养，增强体质' },
            { title: '个性定制', content: '根据个人体质和健康状况，定制专属药膳方案，精准调理' }
          ]
        },
        {
          id: 8,
          name: '苗族食疗',
          category: 'food',
          icon: 'root-list',
          iconColor: '#0052d9',
          tags: ['民族特色', '传统食疗'],
          description: '传承贵州苗族传统食疗文化，采用当地特色食材和草药，制作具有保健功效的苗族特色食品，促进健康。',
          image: 'https://images.unsplash.com/photo-1455619452474-d2be8b1e70cd',
          images: [
            'https://images.unsplash.com/photo-1455619452474-d2be8b1e70cd',
            'https://images.unsplash.com/photo-1540420773420-3366772f4999',
            'https://images.unsplash.com/photo-1563379926898-05f4575a45d8'
          ],
          providers: [
            { id: 15, name: '凯里苗家食疗馆', rating: 4.8, address: '黔东南州凯里市民族路88号' },
            { id: 16, name: '贵阳民族食疗中心', rating: 4.7, address: '贵阳市云岩区瑞金南路135号' }
          ],
          benefits: [
            { title: '特色配方', content: '传承百年苗族食疗配方，采用独特草药和食材组合，具有明显保健功效' },
            { title: '天然健康', content: '选用贵州高山无污染食材和草药，不添加人工添加剂，纯天然健康' },
            { title: '文化体验', content: '体验苗族饮食文化，了解苗医苗药的传统智慧' }
          ]
        }
      ];
      
      this.setData({
        services,
        filteredServices: services
      });
      
      wx.hideLoading();
    }, 500);
  },

  // 搜索框值变化
  onSearchChange: function (e: any) {
    this.setData({
      searchValue: e.detail.value
    });
    this.filterServices();
  },

  // 清除搜索内容
  clearSearch: function () {
    this.setData({
      searchValue: ''
    });
    this.filterServices();
  },

  // 切换分类标签
  changeTab: function (e: any) {
    const tab = e.currentTarget.dataset.tab;
    this.setData({
      activeTab: tab
    });
    this.filterServices();
  },

  // 筛选服务
  filterServices: function () {
    const { services, searchValue, activeTab } = this.data;
    
    let filtered = services;
    
    // 根据分类筛选
    if (activeTab !== 'all') {
      filtered = filtered.filter(item => item.category === activeTab);
    }
    
    // 根据搜索关键词筛选
    if (searchValue) {
      const keyword = searchValue.toLowerCase();
      filtered = filtered.filter(item => 
        item.name.toLowerCase().includes(keyword) || 
        item.description.toLowerCase().includes(keyword) ||
        item.tags.some(tag => tag.toLowerCase().includes(keyword))
      );
    }
    
    this.setData({
      filteredServices: filtered
    });
  },

  // 查看服务详情
  viewServiceDetail: function (e: any) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/service_detail/service_detail?id=${id}`
    });
  }
}) 